<!DOCTYPE html>
<!--头部公共部分-->
{include file="common/header" /}
<form class="layui-form layui-form-pane">
<div style="text-align: center">
        <div class="layui-form-item" style="margin-top: 20px;">
            <div class="layui-inline">
                <span style="color:#000000;"  id="date_num"></span>
                <input type="hidden" id="date_num_" name="date_num" value="">
            </div>
            <div class="layui-inline">
                <span style="color:#000000;"  id="time_num"></span>
                <input type="hidden" id="time_num_" name="time_num" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <div id="date_view"></div>
            </div>
            <div class="layui-inline">
                <div id="time_view"></div>
            </div>
        </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <input class="layui-btn layui-btn-normal" lay-submit lay-filter="form" value="立即提交" readonly>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-primary" id="cancel">取消</button>
        </div>
    </div>
</div>
</form>
<!--底部公共部分-->
{include file="common/footer" /}

<script>
    layui.use(['form', 'element', 'table','laydate', 'layer', 'laytpl'], function () {
        var $ = layui.$,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            element = layui.element,
            layer = layui.layer;

  //      var loading = layer.load();


        //日期
        laydate.render({
            elem:  '#date_view'
            ,type: 'date'
            ,trigger: 'click'
            ,position: 'static'
            ,btns: []
            ,change: function(value, date){ //监听日期被切换
                lay('#date_num').html(value);
                $('#date_num_').val(value);
            }
        });
        //时间
       laydate.render({
            elem:  '#time_view'
            ,type: 'time'
           ,trigger: 'click'
           ,btns: []
            ,position: 'static'
            ,change: function(value, date){ //监听时间被切换
                lay('#time_num').html(value);
               $('#time_num_').val(value);
            }
        });

        //监听提交
        form.on('submit(form)', function (data) {
            var date_num =  $('input[name=date_num]').val();
            if(date_num == null || date_num.length <= 0){
                layer.msg('请选日期');
                return;
            }

            var time_num =  $('input[name=time_num]').val();
            if(time_num == null || time_num.length <= 0){
                layer.msg('请选时间');
                return;
            }


            let field = data.field;
            let student_id = '{$student_id}';
            field.status = 1;
            field.student_id = student_id;
            let isLoad;
            $.ajax({
                url: '{:url("Administration/time_date")}',
                method: "post",
                data: field,
                beforeSend: function () {
                    isLoad = layer.load(0, {
                        shade: false
                    }); //0代表加载的风格，支持0-2
                },
                success: function (result) {
                    if (result.code === 1) {
                        layer.msg(result.msg, {icon: 1, time: result.wait * 1000},function () {
                            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }
                }
            });
            return false;
        });

        $("#cancel").click(function () {
            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        })

    });
</script>

